//
//  ManagerNoticeBtnView.m
//  Marketing
//
//  Created by Hanen 3G 01 on 16/2/26.
//  Copyright © 2016年 Hanen 3G 01. All rights reserved.
//问问

#import "ManagerNoticeBtnView.h"
#import "TopBtn.h"

@interface ManagerNoticeBtnView ()
{
    TopBtn *_lastBtn;
    
    int   lastTag;
}
@end

@implementation ManagerNoticeBtnView
- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        //        [self addSubviews];
        //        self.backgroundColor = [UIColor lightGrayColor];
    }
    return self;
}

- (void)addSubviews
{
}

//不能放到添加视图里面 添加self.leftTitle 因为那时候都没有。
//- (void)setLeftTitle:(NSString *)leftTitle
//{a按时发斯蒂芬  
//    _leftTitle = leftTitle;
//
//          [self.otherNotice setTitle:self.leftTitle forState: UIControlStateNormal];
//}

//- (void)setRightTitle:(NSString *)rightTitle
//{
//    _rightTitle = rightTitle;
//
//    [self.myNotice setTitle:self.rightTitle forState: UIControlStateNormal];
//}
//
//- (void)setLeftAttributeStr:(NSAttributedString *)leftAttributeStr
//{
//    _leftAttributeStr = leftAttributeStr;
//    [self.otherNotice setAttributedTitle:leftAttributeStr forState:UIControlStateNormal];
//}
//
//- (void)setRightAttributeStr:(NSAttributedString *)rightAttributeStr
//{
//    _rightAttributeStr = rightAttributeStr;
//    [self.myNotice setAttributedTitle:rightAttributeStr forState:UIControlStateNormal];
//}

- (void)setBtnTitleArray:(NSArray *)btnTitleArray
{
    _btnTitleArray = btnTitleArray;
    CGFloat btnW = self.width / btnTitleArray.count;
    CGFloat btnH = self.height;
    for (int i = 0; i< self.btnTitleArray.count; i++) {
        TopBtn * btn = [[TopBtn alloc] initWithFrame:CGRectMake(btnW * i, 0, btnW, btnH)];
        btn.backgroundColor = NavBackColor;
        [btn setTitle:self.btnTitleArray[i] forState:UIControlStateNormal];
        [btn setTitleColor:UIColorFromRGB(0xb2bedd) forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:15.0f];
        [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        btn.adjustsImageWhenHighlighted = NO;
        btn.title = self.btnTitleArray[i];
        btn.tag = 9966 + i;
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        if (i == 0) {
            btn.enabled = NO;
            _lastBtn = btn;
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            btn.lineView.backgroundColor = yellowBgColor;
        }
        
        [self addSubview:btn];
    }
    
}
-(void)btnAction:(TopBtn *)sender{
    
    if (sender != _lastBtn) {
        [_lastBtn setTitleColor:UIColorFromRGB(0xb2bedd) forState:UIControlStateNormal];
        _lastBtn.lineView.backgroundColor = NavBackColor;
        [sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        sender.lineView.backgroundColor = yellowBgColor;
        _lastBtn.enabled = YES;
        sender.enabled = NO;
        _lastBtn = sender;
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(changeNoticeViewWithTitle:)]) {
        
        [self.delegate changeNoticeViewWithTitle:sender.currentTitle];
    }
    
}
@end
